Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Commit

Permalink
Fix DB logs
Browse files Browse the repository at this point in the history
now send one message to x numbers can log better.
  • Loading branch information
TrueMoein committed Sep 17, 2017
1 parent 2f8a0e0 commit 720d5f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Controllers/SmsirController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use phplusir\smsir\Smsir;
use phplusir\smsir\SmsirLogs;


class SmsirController extends Controller
{

// the main index page for administrators
public function index() {
$credit = Smsir::credit();
$smsir_logs = SmsirLogs::paginate(config('smsir.in-page'));
$smsir_logs = SmsirLogs::orderBy('id','DESC')->paginate(config('smsir.in-page'));
return view('smsir::index',compact('credit','smsir_logs'));
}

Expand Down
56 changes: 40 additions & 16 deletions src/Smsir.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,26 @@ public static function send(array $messages,array $numbers,$sendDateTime = null)
$result = $client->post('http://restfulsms.com/api/MessageSend',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]);
if(config('smsir.db-log')) {
$res = json_decode($result->getBody()->getContents(),true);
foreach ( array_combine( $messages, $numbers ) as $message => $number ) {
SmsirLogs::create( [
'response' => $res['Message'],
'message' => $message,
'status' => $res['IsSuccessful'],
'from' => config('smsir.line-number'),
'to' => $number,
] );
if(count($messages) === 1) {
foreach ( $numbers as $number ) {
SmsirLogs::create( [
'response' => $res['Message'],
'message' => $messages[0],
'status' => $res['IsSuccessful'],
'from' => config('smsir.line-number'),
'to' => $number,
] );
}
} else {
foreach ( array_combine( $messages, $numbers ) as $message => $number ) {
SmsirLogs::create( [
'response' => $res['Message'],
'message' => $message,
'status' => $res['IsSuccessful'],
'from' => config('smsir.line-number'),
'to' => $number,
] );
}
}
}
return $result->getBody()->getContents();
Expand Down Expand Up @@ -114,14 +126,26 @@ public static function sendToCustomerClub(array $messages,array $numbers,$sendDa
$result = $client->post('http://restfulsms.com/api/CustomerClub/Send',['json'=>$body,'headers'=>['x-sms-ir-secure-token'=>self::getToken()],'connect_timeout'=>30]);
if(config('smsir.db-log')){
$res = json_decode($result->getBody()->getContents(),true);
foreach (array_combine($messages, $numbers) as $message => $number) {
SmsirLogs::create([
'response' => $res['Message'],
'message' => $message,
'status' => $res['IsSuccessful'],
'from' => 'باشگاه مشتریان',
'to' => $number,
]);
if(count($messages) === 1) {
foreach ( $numbers as $number ) {
SmsirLogs::create( [
'response' => $res['Message'],
'message' => $messages[0],
'status' => $res['IsSuccessful'],
'from' => config('smsir.line-number'),
'to' => $number,
] );
}
} else {
foreach ( array_combine( $messages, $numbers ) as $message => $number ) {
SmsirLogs::create( [
'response' => $res['Message'],
'message' => $message,
'status' => $res['IsSuccessful'],
'from' => config('smsir.line-number'),
'to' => $number,
] );
}
}
}
return $result->getBody()->getContents();
Expand Down

0 comments on commit 720d5f5

Please sign in to comment.