public function total()
 {
     $result = Trainer::select(DB::raw('sum(full_time_male) as male,
                                         sum(full_time_female) as female,
                                         sum(full_time_male) + sum(full_time_female) as total'))->where('report_date_id', $this->report_date_id)->where('institution_id', $this->institution_id)->get();
     return $result;
 }
 /**
  * Store the job in the database.
  *
  * Returns the id of the job.
  *
  * @param string $job
  * @param mixed  $data
  * @param int    $delay
  *
  * @return int
  */
 public function storeJob($job, $data, $delay = 0)
 {
     $payload = $this->createPayload($job, $data);
     $database = Config::get('database');
     if ($database['default'] === 'odbc') {
         $row = DB::select(DB::raw("SELECT laq_async_queue_seq.NEXTVAL FROM DUAL"));
         $id = $row[0]->nextval;
         $job = new Job();
         $job->id = $id;
         $job->status = Job::STATUS_OPEN;
         $job->delay = $delay;
         $job->payload = $payload;
         $job->save();
     } else {
         if ($database['default'] === 'mysql') {
             $payload = $this->createPayload($job, $data);
             $job = new Job();
             $job->status = Job::STATUS_OPEN;
             $job->delay = $delay;
             $job->payload = $payload;
             $job->save();
             $id = $job->id;
         }
     }
     return $id;
 }
示例#3
0
 /**
  * 重置密钥
  * @param $key
  */
 public static function reset($key)
 {
     $phptime = date("Y-m-d H:i:s.u");
     $k = substr(str_shuffle(md5(microtime())), rand(1, 5), 18);
     DB::table('passports')->where('key', $key)->update(['secret' => $k, 'updated_at' => $phptime]);
     return 1;
 }
 /**
  * Handle permissions change
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function putAll(Request $request)
 {
     $permissions = Permission::all();
     $input = array_keys($request->input('permissions'));
     try {
         DB::beginTransaction();
         $permissions->each(function ($permission) use($input) {
             if (in_array($permission->id, $input)) {
                 $permission->allow = true;
             } else {
                 $permission->allow = false;
             }
             $permission->save();
         });
         DB::commit();
         flash()->success(trans('permissions.save_success'));
     } catch (\Exception $e) {
         var_dump($e->getMessage());
         die;
         flash()->error(trans('permissions.save_error'));
     }
     try {
         Cache::tags(['permissions'])->flush();
     } catch (\Exception $e) {
         Cache::flush();
     }
     return redirect()->back();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if ($this->confirm("Clear database? [Yes|no]", "Yes")) {
         $this->info('Clear database start');
         if (config('database.default') == 'mysql') {
             DB::statement('SET FOREIGN_KEY_CHECKS=0');
         } else {
             if (config('database.default') == 'sqlite') {
                 DB::statement('PRAGMA foreign_keys = OFF');
             }
         }
         $tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames();
         foreach ($tableNames as $v) {
             Schema::drop($v);
             $this->info('Dropped: ' . $v);
         }
         $this->info('Clear database end');
         if (config('database.default') == 'mysql') {
             DB::statement('SET FOREIGN_KEY_CHECKS=1');
         } else {
             if (config('database.default') == 'sqlite') {
                 DB::statement('PRAGMA foreign_keys = ON');
             }
         }
     }
 }
 public function clear(Request $request)
 {
     $post = $request->all();
     $comment = $post['comment'];
     $value = $post['amount'];
     $student = $post['regNo'];
     $clearedAt = $post['signedAt'];
     $clearedBy = $post['signedBy'];
     $comment = preg_replace('/[^A-Za-z0-9 _]/', '', $comment);
     $value = preg_replace('/[^0-9]/', '', $value);
     DB::beginTransaction();
     $submit = DB::update("UPDATE charge\n            INNER JOIN comments ON charge.students_studentNo = comments.students_studentNo\n            INNER JOIN cleared_at ON charge.students_studentNo = cleared_at.students_studentNo\n            INNER JOIN cleared_by ON charge.students_studentNo = cleared_by.students_studentNo\n            SET\n            charge.cafeteria_value = '{$value}',\n            charge.queueFlag = charge.queueFlag + 1,\n            comments.cafeteria = '{$comment}',\n            cleared_at.cafeteria_cleared_at = '{$clearedAt}',\n            cleared_by.cafeteria_cleared_by = '{$clearedBy}'\n\n            WHERE charge.students_studentNo = '{$student}'\n            AND comments.students_studentNo = '{$student}'\n            AND cleared_at.students_studentNo = '{$student}'\n            AND cleared_by.students_studentNo='{$student}' ");
     if ($submit) {
         DB::commit();
     } else {
         DB::rollBack();
     }
     // $admin = DB::table('departments')
     //         ->join('administrators','departments.administrator','=','administrators.admin_id')
     //         ->select('administrators.email')->where('departments.department_name','=','Library')
     //         ->pluck('email');
     //Send Mail
     // Mail::send('mails.clear', ['student' => $student ], function($message) use($admin){
     //     $message->to($admin)->from('*****@*****.**', 'Strathmore University')->subject('Clearance');
     // });
     return redirect('/cafeteria');
 }
示例#7
0
 public function getMmPoint(Request $request)
 {
     $key = request('key');
     $mmpointM = DB::connection(DBUtils::getDBName())->table('mmpoint_table')->where('A', $key)->first();
     // Log::info("lenth ".sizeof($mmtrendM));
     return response()->json(['mmpointM' => json_encode($mmpointM)]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('roles')->truncate();
     //insert some dummy records
     Role::create(['name' => 'Admin', 'status' => 'active']);
     /*Role::create([
             'name' => 'Project Manager',
             'status' => 'active',
             ]);
     
             Role::create([
             'name' => 'Team Lead',
             'status' => 'active',
             ]);
     
             Role::create([
             'name' => 'Developer',
             'status' => 'active',
             ]);
     
             Role::create([
             'name' => 'Designer',
             'status' => 'active',
             ]);
     
             Role::create([
             'name' => 'Tester',
             'status' => 'active',
             ]);*/
     DB::table('roles_users')->insert(['user_id' => 1, 'role_id' => 1, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
 }
示例#9
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $count = 0;
     $pdo = DB::connection()->getPdo();
     $query = "SELECT * FROM archivos_sat;";
     $stmt = $pdo->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetchObject()) {
         $count++;
         if ($count % 100 == 0) {
             $this->comment("arch sat: " . $count);
         }
         $archivo = ArchivoSat::find($row->id);
         $parser = new ParserCFID($archivo->file);
         $parser->parser();
         $archivo->fecha = $parser->getFecha();
         $archivo->save();
     }
     $count = 0;
     $pdo = DB::connection()->getPdo();
     $query = "SELECT * FROM archivos_empresa;";
     $stmt = $pdo->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetchObject()) {
         $count++;
         if ($count % 100 == 0) {
             $this->comment("arch emp: " . $count);
         }
         $archivo = ArchivoEmpresa::find($row->id);
         $parser = new ParserCFID($archivo->file);
         $parser->parser();
         $archivo->fecha = $parser->getFecha();
         $archivo->save();
     }
 }
 /**
  * @test
  **/
 public function canStartForeignKeysCheckIfSupported()
 {
     $mock_exec = m::mock('StdClass')->shouldReceive('exec')->once()->with('SET FOREIGN_KEY_CHECKS=1;')->getMock();
     $mock_getPdo = m::mock('StdClass')->shouldReceive('getPdo')->once()->andReturn($mock_exec)->getMock();
     DB::shouldReceive('connection')->once()->andReturn($mock_getPdo);
     DbHelperStub::startForeignKeysCheck();
 }
示例#11
0
 public function unlink(Module $module, Request $request, FileRepository $fileRepository, Imagy $imagy)
 {
     DB::table('media__imageables')->whereFileId($request->get('fileId'))->delete();
     $file = $fileRepository->find($request->get('fileId'));
     $imagy->deleteAllFor($file);
     $fileRepository->destroy($file);
 }
示例#12
0
 /**
  * Remove unused avatar files from disk.
  *
  * @return void
  */
 private function purgeOldAvatars()
 {
     // Build up a list of all avatar images
     $avatars = glob(public_path() . '/upload/*/*.*');
     // Remove the public_path() from the path so that they match values in the DB
     array_walk($avatars, function (&$avatar) {
         $avatar = str_replace(public_path(), '', $avatar);
     });
     $all_avatars = collect($avatars);
     // Get all avatars currently assigned
     $current_avatars = DB::table('users')->whereNotNull('avatar')->lists('avatar');
     // Compare the 2 collections get a list of avatars which are no longer assigned
     $orphan_avatars = $all_avatars->diff($current_avatars);
     $this->info('Found ' . $orphan_avatars->count() . ' orphaned avatars');
     // Now loop through the avatars and delete them from storage
     foreach ($orphan_avatars as $avatar) {
         $avatarPath = public_path() . $avatar;
         // Don't delete recently created files as they could be temp files from the uploader
         if (filemtime($avatarPath) > strtotime('-15 minutes')) {
             $this->info('Skipping ' . $avatar);
             continue;
         }
         if (!unlink($avatarPath)) {
             $this->error('Failed to delete ' . $avatar);
         } else {
             $this->info('Deleted ' . $avatar);
         }
     }
 }
 /**
  * Run the migrations.
  */
 public function up()
 {
     Schema::table('deployments', function (Blueprint $table) {
         $table->boolean('is_webhook')->default(false);
     });
     DB::table('deployments')->whereRaw('user_id IS NULL')->update(['is_webhook' => true]);
 }
示例#14
0
 public function run()
 {
     DB::table('partners')->delete();
     Partner::create(['applicant_id' => 1, 'partner' => 'Pepper Potts', 'title' => 'CFO', 'location' => 'Monroe, LA', 'email' => '*****@*****.**', 'phone' => '5125551020']);
     Partner::create(['applicant_id' => 1, 'partner' => 'James Rhodes', 'title' => 'Colonel', 'location' => 'Norfolk, VA', 'email' => '*****@*****.**', 'phone' => '5125559999']);
     Partner::create(['applicant_id' => 4, 'partner' => 'Sam Wilson', 'title' => 'Falcon', 'location' => 'Washington, D.C.', 'email' => '*****@*****.**', 'phone' => '5125995599']);
 }
示例#15
0
 public function run()
 {
     for ($i = 0; $i < 100; $i++) {
         DB::table('posts_has_tags')->insert(['post_id' => $i + 1, 'tag_id' => rand(1, 2)]);
         DB::table('posts_has_tags')->insert(['post_id' => $i + 1, 'tag_id' => rand(3, 4)]);
     }
 }
 public function postLogin(LoginRequest $request)
 {
     if (!Auth::attempt(['email' => $request->get('email'), 'password' => $request->get('password')], true)) {
         session()->flash('errorMessages', ['You have entered an invalid email address or password.', 'Please try again.']);
         return back()->withInput();
     }
     $user = Auth::user();
     // if the user has a plant, set welcome message
     if (count($user->plants)) {
         $plant = $user->plants()->where('isHarvested', '=', false)->orderBy(DB::raw('RAND()'))->first();
         if ($plant) {
             // set welcome message to need water or need fertilizer if the plant needs it
             $lastTimeWatered = $plant->getLastTimeWatered();
             $lastTimeFertilized = $plant->getLastTimeFertilized();
             $random = round(rand(1, 2));
             if (!$lastTimeWatered && $plant->created_at->addDay() < Carbon::now()) {
                 $status = $plant->plantCharacter['need_water_phrase_' . $random];
             } elseif (!$lastTimeFertilized && $plant->created_at->addDay() < Carbon::now()) {
                 $status = $plant->plantCharacter['need_fertilizer_phrase_' . $random];
             } elseif ($lastTimeWatered && Carbon::createFromFormat('Y-m-d H:i:s', $lastTimeWatered->pivot->date)->addDay() < Carbon::now()) {
                 $status = $plant->plantCharacter['need_water_phrase_' . $random];
             } elseif ($lastTimeFertilized && Carbon::createFromFormat('Y-m-d H:i:s', $lastTimeFertilized->pivot->date)->addDay() < Carbon::now()) {
                 $status = $plant->plantCharacter['need_fertilizer_phrase_' . $random];
             } else {
                 $status = $plant->plantCharacter['welcome_phrase_' . $random];
             }
             session()->flash('message', $plant->plantCharacter->name . ': ' . $status);
         }
     }
     return redirect()->route('dashboard');
 }
示例#17
0
 public function run()
 {
     if (env('DB_DRIVER') == 'mysql') {
         DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     }
     if (env('DB_DRIVER') == 'mysql') {
         DB::table(config('access.roles_table'))->truncate();
     } else {
         //For PostgreSQL or anything else
         DB::statement("TRUNCATE TABLE " . config('access.roles_table') . " CASCADE");
     }
     //Create admin role, id of 1
     $role_model = config('access.role');
     $admin = new $role_model();
     $admin->name = 'Administrator';
     $admin->all = true;
     $admin->sort = 1;
     $admin->created_at = Carbon::now();
     $admin->updated_at = Carbon::now();
     $admin->save();
     //id = 2
     $role_model = config('access.role');
     $user = new $role_model();
     $user->name = 'User';
     $user->sort = 2;
     $user->created_at = Carbon::now();
     $user->updated_at = Carbon::now();
     $user->save();
     if (env('DB_DRIVER') == 'mysql') {
         DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     }
 }
示例#18
0
 /**
  * @return mixed
  */
 public function showNews()
 {
     $slug = Request::segment(2);
     $news_title = "Not active";
     $news_text = "Either this news item is not active, or it does not exist";
     $active = 1;
     $news_id = 0;
     $results = DB::table('news')->where('slug', '=', $slug)->get();
     foreach ($results as $result) {
         $active = $result->active;
         if ($active > 0 || Auth::check() && Auth::user()->hasRole('news')) {
             if (Session::get('lang') == null || Session::get('lang') == "en") {
                 $news_title = $result->title;
                 $news_text = $result->news_text;
                 $news_id = $result->id;
             } else {
                 $news_title = $result->title_fr;
                 $news_text = $result->news_text_fr;
                 $news_id = $result->id;
             }
             $news_image = $result->image;
             $news_date = $result->news_date;
         }
     }
     return View::make('public.news')->with('news_title', $news_title)->with('news_text', $news_text)->with('page_content', $news_text)->with('active', $active)->with('news_id', $news_id)->with('news_date', $news_date)->with('news_image', $news_image)->with('menu', $this->menu)->with('page_category_id', 0)->with('page_title', $news_title);
 }
示例#19
0
 /**
  * Run the Update
  *
  * @return mixed|void
  */
 public function call()
 {
     $pheal = $this->setScope('char')->getPheal();
     foreach ($this->api_info->characters as $character) {
         // Get a list of messageIDs that we do not have mail
         // bodies for. These ID's will be used to try and
         // pull the bodies using this api key
         $message_ids = DB::table('character_mail_messages')->where('characterID', $character->characterID)->whereNotIn('messageID', function ($query) {
             $query->select('messageID')->from('character_mail_message_bodies');
         })->lists('messageID');
         // It is possible to provide a comma seperated list
         // of messageIDs to the MailBodies endpoint. Pheal
         // caches XML's on disk by file name. To prevent file
         // names from becoming too long, we will chunk the
         // ids we want to update.
         foreach (array_chunk($message_ids, 10) as $message_id_chunk) {
             $result = $pheal->MailBodies(['characterID' => $character->characterID, 'ids' => implode(',', $message_id_chunk)]);
             foreach ($result->messages as $body) {
                 MailMessageBody::create(['messageID' => $body->messageID, 'body' => $body->__toString()]);
             }
         }
         // Foreach messageID chunk
     }
     return;
 }
 public function materiaMaestroEnpalme()
 {
     $maestroId = Materia::join('maestro_materia', 'materias.id', '=', 'maestro_materia.materia_id')->where('materia_id', '=', Input::get('materia_id'))->select('materia', 'materia_id', 'maestro_id')->first();
     $maestroMateria = DB::table('horarios')->join('materias', 'materias.id', '=', 'horarios.materia_id')->join('maestro_materia', 'maestro_materia.materia_id', '=', 'materias.id')->join('maestros', 'maestros.id', '=', 'maestro_materia.maestro_id')->where('hora_id', Input::get('hora_id'))->where('horarios.ciclo_id', Input::get('ciclo_id'))->where('dia_id', Input::get('dia_id'))->where('maestro_id', $maestroId->maestro_id)->get();
     //dd($maestroMateria);
     return $maestroMateria;
 }
示例#21
0
 public function refresh($town)
 {
     $town_id = DB::table('towns')->where('town', $town)->first();
     $town_id = $town_id->id;
     //получить id города
     $response = json_decode(file_get_contents('http://api.openweathermap.org/data/2.5/forecast?q=' . $town . '&mode=json&appid=f84ba1064b0ae65792326548686f361c'), true);
     //  print_r($response);
     $id = $response['city']['id'];
     $date_today = date("Y-m-d", strtotime("+0 day"));
     DB::table('weather')->where('kuupaev', '>=', $date_today)->where('town_id', $town_id)->delete();
     for ($i = 0; $i < sizeof($response['list']); $i++) {
         $date = date("Y-m-d H:i:s", $response['list'][$i]['dt']);
         $temp_min = $response['list'][$i]['main']['temp_min'];
         $temp_max = $response['list'][$i]['main']['temp_max'];
         $temp_min = round($temp_min - 273.15);
         $temp_max = round($temp_max - 273.15);
         $weather = new Weather();
         $weather->town_id = $id;
         $weather->temp_min = $temp_min;
         $weather->temp_max = $temp_max;
         $weather->kuupaev = $date;
         $weather->save();
     }
     return redirect('weather/' . $town);
 }
示例#22
0
 public function run()
 {
     DB::table('master_type_bank')->delete();
     $data = array(array('name' => 'TABUNGAN', 'info' => '', 'uuid' => uniqid(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime(), 'createby_id' => 1, 'lastupdateby_id' => 1), array('name' => 'GIRO', 'info' => '', 'uuid' => uniqid(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime(), 'createby_id' => 1, 'lastupdateby_id' => 1), array('name' => 'DEPOSITO', 'info' => '', 'uuid' => uniqid(), 'created_at' => new \DateTime(), 'updated_at' => new \DateTime(), 'createby_id' => 1, 'lastupdateby_id' => 1));
     DB::table('master_type_bank')->insert($data);
     $this->command->info('Done [' . __CLASS__ . ']');
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     DB::table('favorites')->whereNotNull('deleted_at')->delete();
     Schema::table('favorites', function (Blueprint $table) {
         $table->dropColumn('deleted_at');
     });
 }
示例#24
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('tags')->insert(['title' => "camiseta"]);
     DB::table('tags')->insert(['title' => "preta"]);
     DB::table('tags')->insert(['title' => "branca"]);
     DB::table('tags')->insert(['title' => "amarela"]);
 }
示例#25
0
 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $builder
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function apply(Builder $builder, Model $model)
 {
     if (isset($model->workend)) {
         $end = $model->workend;
     } else {
         $end = 'now';
     }
     $prefix_person = 'hrps_';
     //env('DB_PREFIX_HR_PERSON');
     $prefix_empl = 'hres_';
     //env('DB_PREFIX_HR_EMPLOYMENT');
     $prefix_org = 'hrom_';
     //env('DB_PREFIX_HR_ORGANISATION');
     $builder->selectraw('CONCAT(' . $prefix_org . 'charts.name, " cabang ", ' . $prefix_org . 'branches.name) as newest_position')->selectraw($prefix_org . 'branches.organisation_id as organisation_id')->selectraw($prefix_org . 'charts.department as newest_department')->selectraw($prefix_empl . 'works.id as newest_work_id')->selectraw($prefix_empl . 'works.nik as newest_nik')->selectraw($prefix_empl . 'works.status as newest_status')->selectraw($prefix_empl . 'works.start as newest_work_start')->selectraw($prefix_empl . 'works.end as newest_work_end')->join(DB::raw($prefix_empl . 'works'), function ($join) use($end, $prefix_empl, $prefix_person) {
         $join->on(DB::raw($prefix_person . 'persons.id'), '=', DB::raw($prefix_empl . 'works.person_id'))->where(function ($query) use($end, $prefix_empl) {
             $query->where(function ($query) use($end, $prefix_empl) {
                 $query;
                 // $query->wherenull( DB::raw($prefix_empl.'works.end'))
                 // ->orwhere( DB::raw($prefix_empl.'works.end'), '>=', date('Y-m-d H:i:s', strtotime($end)));
             })->wherenull(DB::raw($prefix_empl . 'works.deleted_at'));
         });
     })->join(DB::raw($prefix_org . 'charts'), function ($join) use($prefix_empl, $prefix_org) {
         $join->on(DB::raw($prefix_empl . 'works.chart_id'), '=', DB::raw($prefix_org . 'charts.id'))->wherenull(DB::raw($prefix_org . 'charts.deleted_at'));
     })->join(DB::raw($prefix_org . 'branches'), function ($join) use($prefix_org) {
         $join->on(DB::raw($prefix_org . 'charts.branch_id'), '=', DB::raw($prefix_org . 'branches.id'))->wherenull(DB::raw($prefix_org . 'branches.deleted_at'));
     })->groupby(DB::raw($prefix_person . 'persons.id'));
 }
示例#26
0
 public function run()
 {
     if (env('DB_DRIVER') == 'mysql') {
         DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     }
     if (env('DB_DRIVER') == 'mysql') {
         DB::table(config('access.assigned_roles_table'))->truncate();
     } elseif (env('DB_DRIVER') == 'sqlite') {
         DB::statement("DELETE FROM " . config('access.assigned_roles_table'));
     } else {
         //For PostgreSQL or anything else
         DB::statement("TRUNCATE TABLE " . config('access.assigned_roles_table') . " CASCADE");
     }
     //Attach admin role to admin user
     $user_model = config('auth.model');
     $user_model = new $user_model();
     $user_model::first()->attachRole(1);
     //Attach user role to general user
     $user_model = config('auth.model');
     $user_model = new $user_model();
     $user_model::find(2)->attachRole(2);
     if (env('DB_DRIVER') == 'mysql') {
         DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     }
 }
 public function keywords()
 {
     $limit = 25;
     $projections = array('id', 'value');
     $keywords = DB::collection('map_reduce_twitter_words')->orderBy('value', 'desc')->paginate($limit, $projections);
     return view('keywords')->with(['keywords' => $keywords]);
 }
示例#28
0
 public function save()
 {
     if (!$this->product_id) {
         return Category::find($this->category)->product()->create($this->fields());
     }
     return DB::table('products')->where('id', $this->product_id)->update(['category_id' => $this->category, 'name' => $this->name, 'type' => $this->type, 'length' => $this->length, 'thickness' => $this->thickness, 'width' => $this->width, 'description' => $this->description, 'hidden' => $this->hidden]);
 }
示例#29
0
 /**
  * Returns the sum of all values a metric has by the hour.
  *
  * @param int $hour
  *
  * @return int
  */
 public function getValuesByHour($hour)
 {
     $dateTimeZone = SettingFacade::get('app_timezone');
     $dateTime = (new Date())->setTimezone($dateTimeZone)->sub(new DateInterval('PT' . $hour . 'H'));
     $hourInterval = $dateTime->format('YmdH');
     if (Config::get('database.default') === 'mysql') {
         if (!isset($this->calc_type) || $this->calc_type == self::CALC_SUM) {
             $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%d%H") = ' . $hourInterval)->groupBy(DB::raw('HOUR(created_at)'))->sum('value');
         } elseif ($this->calc_type == self::CALC_AVG) {
             $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%d%H") = ' . $hourInterval)->groupBy(DB::raw('HOUR(created_at)'))->avg('value');
         }
     } else {
         // Default metrics calculations.
         if (!isset($this->calc_type) || $this->calc_type == self::CALC_SUM) {
             $queryType = 'sum(metric_points.value)';
         } elseif ($this->calc_type == self::CALC_AVG) {
             $queryType = 'avg(metric_points.value)';
         } else {
             $queryType = 'sum(metric_points.value)';
         }
         $query = DB::select("select {$queryType} as aggregate FROM metrics JOIN metric_points ON metric_points.metric_id = metrics.id WHERE metric_points.metric_id = {$this->id} AND to_char(metric_points.created_at, 'YYYYMMDDHH24') = :timestamp GROUP BY to_char(metric_points.created_at, 'H')", ['timestamp' => $hourInterval]);
         if (isset($query[0])) {
             $value = $query[0]->aggregate;
         } else {
             $value = 0;
         }
     }
     if ($value === 0 && $this->default_value != $value) {
         return $this->default_value;
     }
     return $value;
 }
示例#30
-1
 public function postSendsms(Request $request)
 {
     $mobile = Input::get('mobile');
     if (!preg_match("/1[3458]{1}\\d{9}\$/", $mobile)) {
         // if(!preg_match("/^13\d{9}$|^14\d{9}$|^15\d{9}$|^17\d{9}$|^18\d{9}$/",$mobile)){
         //手机号码格式不对
         return parent::returnJson(1, "手机号码格式不对" . $mobile);
     }
     $data = DB::select("select * from members where lifestatus=1 and mobile =" . $mobile);
     if (sizeof($data) > 0) {
         return parent::returnJson(1, "手机号已注册");
     }
     $checkCode = parent::get_code(6, 1);
     Session::put("m" . $mobile, $checkCode);
     $checkCode = Session::get("m" . $mobile);
     Log::error("sendsms:session:" . $checkCode);
     $msg = "尊敬的用户:" . $checkCode . "是您本次的短信验证码,5分钟内有效.";
     // Input::get('msg');
     $curl = new cURL();
     $serverUrl = "http://cf.lmobile.cn/submitdata/Service.asmx/g_Submit";
     $response = $curl->get($serverUrl . "?sname=dlrmcf58&spwd=ZRB2aP8K&scorpid=&sprdid=1012818&sdst=" . $mobile . "&smsg=" . rawurlencode($msg . "【投贷宝】"));
     $xml = simplexml_load_string($response);
     echo json_encode($xml);
     //$xml->State;
     //  <CSubmitState xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
     //   <State>0</State>
     //   <MsgID>1512191953407413801</MsgID>
     //   <MsgState>提交成功</MsgState>
     //   <Reserve>0</Reserve>
     // </CSubmitState>
     // <State>1023</State>
     //  <MsgID>0</MsgID>
     //  <MsgState>无效计费条数,号码不规则,过滤[1:186019249011,]</MsgState>
     //  <Reserve>0</Reserve>
 }