public function testAction() { $str = date('Y-m-d H:i:s'); $sheduled_sms = SheduleSms::find(array('conditions' => "shedule_date <= '{$str}' AND status ='SHEDULED' ", 'columns' => 'id, sms_id,shedule_date')); if ($sheduled_sms->count() > 0) { foreach ($sheduled_sms as $shedule_sms) { $cmd = 'php ' . __DIR__ . '/../../app/cli.php publish publish ' . $shedule_sms->sms_id; exec('nohup ' . $cmd . ' > /dev/null 2>&1 &'); } } else { echo 'Shedule SMS not found'; } }
public function publishAction(array $params) { if (isset($params[0])) { $id = $params[0]; $sms_data = SmsHistory::findFirst("id ='{$id}' AND status ='PENDING'"); if ($sms_data) { $user_id = $sms_data->user_id; $user = Users::findFirst("id = '{$user_id}'"); if ($user->smsbalance->balance >= $sms_data->billcredit) { switch ($sms_data->type) { case 'GROUPID': $result = Groups::getGroupNumber(json_decode($sms_data->reciever)); break; case 'NUMBER': $result = implode(',', json_decode($sms_data->reciever)); break; case 'CONTACTID': $result = Contacts::getNumbers(json_decode($sms_data->reciever)); break; } $data = $this->sendSMSRequest(array("message" => urldecode($sms_data->message), 'sender_id' => $user->sender_id, 'contacts' => explode(',', $result))); $sms_data->status = "SUCCESS"; $user->smsbalance->balance = $user->smsbalance->balance - $sms_data->billcredit; $user->smsbalance->used = $user->smsbalance->used + $sms_data->billcredit; $user->smsbalance->save(); } else { $sms_data->status = "FAILED"; } $sheduled_sms = SheduleSms::findFirst("sms_id = '{$id}'"); if ($sheduled_sms->id) { $sheduled_sms->delete(); } $sms_data->created_at = date("Y-m-d H:i:s"); $sms_data->updated_at = date("Y-m-d H:i:s"); $sms_data->save(); } else { echo "\n Task Not Found \n"; } } }
private function sheduleSMSProcessData($smsdata) { $sms_length = strlen($smsdata['message']); $sms_credit = ($sms_length - $sms_length % 160) / 160 + 1; $user_id = $smsdata['user_id']; $user = Users::findFirst("id = '{$user_id}'"); $count = count($smsdata['contacts']); $billcredit_sms = $count * $sms_credit; if (empty($user->sender_id)) { $sender_id = 'SMHAWK'; } else { $sender_id = $user->sender_id; } $group_id = 0; if ($smsdata['type'] == "GROUPID") { $group_id = implode(',', $smsdata['ids']); } $sms_history = new SmsHistory(); $sms_history->assign(array('user_id' => $user_id, 'group_id' => $group_id, 'reciever' => json_encode($smsdata['ids']), 'contact_ids' => json_encode($smsdata['ids']), 'message' => urlencode($smsdata['message']), 'billcredit' => $billcredit_sms, 'count' => $count, 'type' => $smsdata['type'], 'status' => "PENDING", 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"))); if ($sms_history->save()) { $shedulesms = new SheduleSms(); $shedulesms->assign(array('sms_id' => $sms_history->id, 'shedule_date' => $smsdata['schedule_date'], 'status' => "SHEDULED", 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"))); $shedulesms->save(); } $data = array('status' => 'success', 'id' => $shedulesms->id, 'msg' => 'Message has been Shedule', 'code' => 2); return $data; }